package cn.haoxsf.app.system.service.impl;

import cn.haoxsf.app.common.api.enums.SystemExceptionEnum;
import cn.haoxsf.app.common.exception.BaseException;
import cn.haoxsf.app.common.util.ToolUtil;
import cn.haoxsf.app.system.entity.FaultCategory;
import cn.haoxsf.app.system.mapper.FaultCategoryMapper;
import cn.haoxsf.app.system.model.vo.FaultCategoryVo;
import cn.haoxsf.app.system.service.IFaultCategoryService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 故障类目 服务实现类
 * </p>
 *
 * @author Ele  qvbanfm@qq.com
 * @since 2020-03-15
 */
@Service
public class FaultCategoryServiceImpl extends ServiceImpl<FaultCategoryMapper, FaultCategory> implements IFaultCategoryService {


    /**
     * 按照categoryCode 查询类目
     *
     * @param categoryCode 查询类目代码
     * @return 结果
     */
    @Override
    public FaultCategory getFaultCategoryByCategoryCode(String categoryCode) {
        FaultCategory faultCategory = baseMapper.selectOne(new QueryWrapper<FaultCategory>().eq("category_code", categoryCode));
        if(ToolUtil.isEmpty(faultCategory)){
            throw new BaseException(SystemExceptionEnum.THE_PROJECT_IS_NOT_ENABLED);
        }
        if("ENABLE".equals(faultCategory.getCategoryState())){
           return faultCategory;
        }else {
            throw new BaseException(SystemExceptionEnum.THE_PROJECT_IS_NOT_ENABLED);
        }
    }
}
